package com.example.smallmall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.smallmall.entity.SpMenus;
import com.example.smallmall.mapper.SpMenusMapper;
import com.example.smallmall.service.ISpMenusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author WSGL
 * @since 2020-07-23
 */
@Service
public class SpMenusServiceImpl extends ServiceImpl<SpMenusMapper,SpMenus> implements ISpMenusService {

    @Resource
    private SpMenusMapper spMenusMapper;

    @Override
    public List<Map<String,Object>> selectAllMenu() {
        List<Map<String,Object>> maps = spMenusMapper.selectMaps(new QueryWrapper<SpMenus>().eq("parent_id", 0));
        for (Map<String, Object> map : maps) {
            List<SpMenus> spMenus = spMenusMapper.selectList(new QueryWrapper<SpMenus>().eq("parent_id", map.get("menusId")));
            map.remove("parentId");
            map.put("children", spMenus);
        }
        return maps;
    }
}
